package com.zp.self.module.令牌桶.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zp.self.annotation.DBSelect;
import com.zp.self.module.令牌桶.entity.TestUser;
import com.zp.self.module.令牌桶.mapper.TestUserMapper;
import com.zp.self.多数据源工具.DataSourceConstants;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 服务类，数据源注解在方法
 *
 * @author: mason
 * @since: 2020/1/9
 **/
@Service
public class TestUserService extends ServiceImpl<TestUserMapper, TestUser> implements ISysUserService{

    /**
     * 查询master库User
     */
    @DBSelect()
    public List<TestUser> getMasterUser(){
        QueryWrapper<TestUser> queryWrapper = new QueryWrapper<>();
        return this.list(queryWrapper.isNotNull("name"));
    }

    /**
     * 查询slave库User
     */
    @DBSelect(DataSourceConstants.DS_KEY_SLAVE)
    public List<TestUser> getSlaveUser(){
        return this.list();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public TestUser add(TestUser testUser) {
        this.saveOrUpdate(testUser);
        System.out.println(1/0);
        return testUser;
    }
}
